//
//  ViewController.m
//  纯代码
//
//  Created by student on 16/2/18.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIAlertViewDelegate,UIActionSheetDelegate>

@end

@implementation ViewController

-(void) addbuttonWithTitle:(NSString *)title andTag:(int)tag andColor:(UIColor *)color andFrame:(CGRect)frame
{
    UIButton *btn=[[UIButton alloc]initWithFrame:frame];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:color forState:UIControlStateNormal];
    btn.titleLabel.font=[UIFont systemFontOfSize:15];
    btn.tag=tag;
    [btn addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.lable=[[UILabel alloc]initWithFrame:CGRectMake(50, 200, 200, 50)];
    self.lable.text=@"lable";
    self.lable.textColor=[UIColor redColor];
    [self.view addSubview:self.lable];
    [self addbuttonWithTitle:@"简单提示框" andTag:1 andColor:[UIColor redColor] andFrame:CGRectMake(10, 50, 100, 50)];
    [self addbuttonWithTitle:@"多按钮" andTag:2 andColor:[UIColor greenColor] andFrame:CGRectMake(10, 100, 100, 50)];
    [self addbuttonWithTitle:@"带输入框" andTag:3 andColor:[UIColor blueColor] andFrame:CGRectMake(10, 150, 100, 50)];
    [self addbuttonWithTitle:@"操作表" andTag:4 andColor:[UIColor blueColor] andFrame:CGRectMake(10, 250, 100, 50)];
    
}
-(void)btnPressed:(UIButton *)sender
{
    if(sender.tag==1)
    {
        UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"判断" message:@"我长得帅吗" delegate:self cancelButtonTitle:@"帅的" otherButtonTitles:nil];
        
        [alertView show];


    }
    else if(sender.tag==2)
    {
        UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"判断" message:@"我长得帅吗" delegate:self cancelButtonTitle:@"帅的" otherButtonTitles:@"超帅",@"非常帅",nil];
        
        [alertView show];

    }
    else if (sender.tag==3)
    {
        UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"登录" message:@"请输入账号密码" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消",nil];
        alertView.alertViewStyle=UIAlertViewStyleLoginAndPasswordInput;
        [alertView show];

    }
    else
    {
        UIActionSheet *sheet=[[UIActionSheet alloc]initWithTitle:@"亚古兽进化" delegate:self cancelButtonTitle:@"丧尸暴龙兽" destructiveButtonTitle:@"战斗暴龙兽" otherButtonTitles:@"暴龙兽",@"机械暴龙兽",nil];
        [sheet showInView:self.view];
    }
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"点了第几个按钮=%i,按钮的文字是:%@",buttonIndex+1,[alertView buttonTitleAtIndex:buttonIndex]);
    NSLog(@"弹窗的信息是:%@",alertView.title);
    if([alertView.title isEqualToString:@"登录"])
    {
        NSString *info=[NSString stringWithFormat:@"账号:%@ 密码:%@",[alertView textFieldAtIndex:0].text,[alertView textFieldAtIndex:1].text];
        self.lable.text=info;
    }
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"操作表的标题:%@",actionSheet.title);
    NSLog(@"用户选择了哪一个按钮:%i,%@",buttonIndex,[actionSheet buttonTitleAtIndex:buttonIndex]);
    
    if(buttonIndex == actionSheet.destructiveButtonIndex)
    {
        NSLog(@"用户点了destructiveBtn");
        NSLog(@"进化成了%@",[actionSheet buttonTitleAtIndex:buttonIndex]);
    }
    else if(buttonIndex == actionSheet.cancelButtonIndex)
    {
        NSLog(@"用户点了cancelBtn");
        NSLog(@"进化成了%@",[actionSheet buttonTitleAtIndex:buttonIndex]);
    }
    else
    {
        NSLog(@"进化成了%@",[actionSheet buttonTitleAtIndex:buttonIndex]);
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
